import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;

public class addHouse extends HttpServlet
{
	public static dbapi conn;
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
	{
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		conn = new dbapi();
		conn.connect();
		if(conn.connected)
			out.println("connected via dbapi <br>");
		else
		{
			out.println("CANT CONNECT! <br>");
			out.println(conn.msg + "<br>");
			return;
		}
		String address = request.getParameter("ADDRESS");
		String city = request.getParameter("CITY");
		String state = request.getParameter("STATE");
		String zipcode = request.getParameter("ZIPCODE");
		String floorSpace = request.getParameter("SQFT");
		String numFloors = request.getParameter("FLOORS");
		String numBedrooms = request.getParameter("BEDROOMS");
		String numBathrooms = request.getParameter("BATHROOMS");
		String landSize	= request.getParameter("LANDSIZE");
		String year = request.getParameter("YEAR");
		
		if(floorSpace == "" || numFloors == "" || numBedrooms == ""
		|| numBathrooms == "" || landSize == "" || year == "" 
		|| address == "" || city == "" || state == "" || zipcode == "")
		{
			out.println("ERROR: not all fields were filled in");
			return;
		}
		boolean worked = conn.newHome(
				address,
				city,
				state,
				Integer.parseInt(zipcode),
				Integer.parseInt(floorSpace),
				Integer.parseInt(numFloors),
				Integer.parseInt(numBedrooms),
				Integer.parseInt(numBathrooms),
				Integer.parseInt(landSize),
				Integer.parseInt(year));
		if(!worked)
		{
			out.println(conn.msg);
		}else{
			out.println("it worked");
		}
		return;
	}
}
